unit gomide;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DB, DBTables, Grids, DBGrids, Menus, ComCtrls;

type
  Tfprincipal = class(TForm)
    Dbcontas: TDataSource;
    Contasdb: TTable;
    dbfcontas: TDataSource;
    contasdbf: TTable;
    contasdbfCODI: TSmallintField;
    contasdbfNOME: TStringField;
    contasdbfACUM: TStringField;
    contasdbfSALD: TFloatField;
    contasdbfPREV: TFloatField;
    contasdbfATUA: TFloatField;
    contasdbfDATA: TDateField;
    contasdbfANTERIOR: TFloatField;
    contasdbfDEBITO: TFloatField;
    contasdbfCREDITO: TFloatField;
    ContasdbCodigo: TStringField;
    ContasdbNome: TStringField;
    ContasdbData: TDateField;
    ContasdbSaldoinicial: TFloatField;
    ContasdbSaldoatual: TFloatField;
    dbhp: TDataSource;
    hpdb: TTable;
    dbfhp: TDataSource;
    hpdbf: TTable;
    hpdbCodigo: TFloatField;
    hpdbNome: TStringField;
    hpdbfCODIGO: TSmallintField;
    hpdbfHISTOR: TStringField;
    StatusBar1: TStatusBar;
    MainMenu1: TMainMenu;
    Clientes1: TMenuItem;
    Contas1: TMenuItem;
    Histricos1: TMenuItem;
    Lancamentos1: TMenuItem;
    Pagamentos1: TMenuItem;
    Recebimentos1: TMenuItem;
    Fim1: TMenuItem;
    Fim2: TMenuItem;
    Razao1: TMenuItem;
    Cheques1: TMenuItem;
    Saldos1: TMenuItem;
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure Fim2Click(Sender: TObject);
    procedure Histricos1Click(Sender: TObject);
    procedure Lancamentos1Click(Sender: TObject);
    procedure Contas1Click(Sender: TObject);
    procedure Saldos1Click(Sender: TObject);
    procedure Clientes1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fprincipal: Tfprincipal;

implementation

uses razao, contas, hp, diario, saldos, relsaldos, relsaldos0, clientes;

{$R *.dfm}

procedure Tfprincipal.BitBtn6Click(Sender: TObject);
begin
close;
end;


procedure Tfprincipal.BitBtn4Click(Sender: TObject);
begin
frazao.ShowModal;
end;

procedure Tfprincipal.FormShow(Sender: TObject);
var mcodigo, mnome, mdata : string;
var msaldo, minicial : currency;
var mhp : integer;
begin
while contasdb.RecordCount > 0 do
 contasdb.Delete;

//contasdb.emptytable;
contasdbf.First;
while not contasdbf.Eof do
 begin
 mcodigo  := contasdbfcodi.asstring;
 mcodigo  := copy(mcodigo,1,2) + '00' + copy(mcodigo,3,2);
 if strtoint(copy(mcodigo,3,4)) = 0 then mcodigo := copy(mcodigo,1,2);
 mnome    := uppercase(contasdbfnome.value);
 mdata    := contasdbfdata.asstring;
 msaldo   := contasdbfsald.value;
 minicial := 0;
 if not contasdb.findkey([mcodigo]) then
    contasdb.insertrecord([mcodigo,mnome,mdata,msaldo,minicial])
 else
    begin
    contasdb.edit;
    contasdbnome.value := mnome;
//    contasdbdata.value := mdata;
    contasdbsaldoinicial.value := msaldo;
    contasdb.post;
    end;
 contasdbf.Next;
end;
hpdbf.open;
hpdb.open;
hpdbf.First;
while not hpdbf.Eof do
 begin
 mhp      := hpdbfcodigo.value;
 mnome    := uppercase(hpdbfhistor.value);
 if not hpdb.findkey([mhp]) then
    hpdb.insertrecord([mhp,mnome])
 else
    begin
    hpdb.edit;
    hpdbnome.value := mnome;
    hpdb.Post;
    end;
 hpdbf.Next;
end;




end;

procedure Tfprincipal.BitBtn1Click(Sender: TObject);
begin
fcontas.showmodal;
end;

procedure Tfprincipal.BitBtn2Click(Sender: TObject);
begin
fhp.showmodal;
end;

procedure Tfprincipal.BitBtn3Click(Sender: TObject);
begin
fdiario.showmodal;
end;

procedure Tfprincipal.Fim2Click(Sender: TObject);
begin
close;
end;



procedure Tfprincipal.Histricos1Click(Sender: TObject);
begin
fhp.ShowModal;
end;

procedure Tfprincipal.Lancamentos1Click(Sender: TObject);
begin
fdiario.ShowModal;
end;

procedure Tfprincipal.Contas1Click(Sender: TObject);
begin
fcontas.ShowModal;
end;

procedure Tfprincipal.Saldos1Click(Sender: TObject);
begin
fsaldos.showmodal;
end;


procedure Tfprincipal.Clientes1Click(Sender: TObject);
begin
fclientes.ShowModal;
end;

end.
